package com.link.base.tencent.thirdclient.qq.controller;

import com.link.core.cllog.LCLogger;
import com.link.base.tencent.thirdclient.qq.model.QQLogin;
import com.link.base.tencent.thirdclient.qq.service.QQLoginService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * QQ登录控制器
 *
 * @author LiQun
 * @date 2018/3/15 11:19
 */
@RestController
@RequestMapping("/qq/login")
public class QQLoginController {

    @Resource
    private QQLoginService qqLoginService;

    /**
     * 基于userId和access_token验证合法性
     *
     * @author LiQun
     * @date 2018/3/15 11:19
     */
    @RequestMapping(value = "getQqInfo")
    @ResponseBody
    private Map<String, Object> ssoLogin(@RequestBody QQLogin qqLogin) {
        Map<String, Object> result = new HashMap<>();

        try {
            qqLogin = qqLoginService.getQqInfo(qqLogin);
            result.put("result", qqLogin);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("message", e.getMessage());
            result.put("success", false);
        }
        return result;
    }
}
